package cn.tuling.standard;

/**
 * 常规模式
 */
public class StrategyTest {
    public static void main(String[] args) {
        Context context = new Context();
        context.setStrategy(new ConcreteStrategyA());
        context.strategyMethod();

        System.out.println("-------------");

        context.setStrategy(new ConcreteStrategyB());
        context.strategyMethod();
    }
}

interface Strategy {
    void strategyMethod();
}

class ConcreteStrategyA implements Strategy {

    @Override
    public void strategyMethod() {
        System.out.println("策略A的方法");
    }
}

class ConcreteStrategyB implements Strategy {

    @Override
    public void strategyMethod() {
        System.out.println("策略B的方法");
    }
}

class Context {
    private Strategy strategy;

    public void setStrategy(Strategy strategy) {
        this.strategy = strategy;
    }

    public void strategyMethod() {
        strategy.strategyMethod();
    }
}